import React, { Component } from 'react';
import { CommonTable } from 'components';
import { CopyToClipboard } from 'react-copy-to-clipboard';
import SearchList from './SearchList/SearchList';
import moment from 'moment';
import { axios } from 'utils';
import {Icon, Modal, Tooltip, Button, Input, Row, Col, message, Table} from "antd";

class YiBaoId extends Component {
    constructor(props) {
        super(props);
        this.state = {
            data: [],
            loading: false,
            visible: false,
            inputVal: '',
            id: '',
            params: {}
        }
        const _this = this;
        this.columns = [
            {
                title: '绑定订单号',
                dataIndex: 'orderNo',
                key: 'orderNo',
                render(text) {
                    return (
                        <CopyToClipboard text={text} onCopy={_this.onCopy}>
                            <Tooltip title={'点击复制'}>
                                <span style={{cursor: 'pointer'}}>{text}</span>
                            </Tooltip>
                        </CopyToClipboard>
                    );

                }
            },
            { title: '姓名', dataIndex: 'userName', key: 'userName' },
            { title: '面额', dataIndex: 'denomination', key: 'denomination' },
            { title: '售价', dataIndex: 'price', key: 'price' },
            {
                title: '有效期',
                dataIndex: 'endTime',
                key: 'endTime', 
                render(text) {
                    return moment(Number(text)).format('YYYY-MM-DD HH:mm:ss');
                }
            },
            {
                title: '状态',
                dataIndex: 'state',
                key: 'state',
                render(text) {
                    return Number(text) === 1 ? '可用' : '不可用'
                }
            },
            {
                title: '类型',
                dataIndex: 'cType',
                key: 'cType',
                render(text) {
                    return Number(text) === 1 ? '消费购买型' : '免费赠送型'
                }
            },
            {
                title: '易宝订单号',
                dataIndex: 'yborderid',
                key: 'yborderid',
                render(text) {
                    return (
                        <CopyToClipboard text={text} onCopy={_this.onCopy}>
                            <Tooltip title={'点击复制'}>
                                <span style={{cursor: 'pointer'}}>{text}</span>
                            </Tooltip>
                        </CopyToClipboard>
                    );

                }
            },
            {
                title: '生成时间',
                dataIndex: 'createTime',
                key: 'createTime',
                render(text) {
                    return moment(Number(text)).format('YYYY-MM-DD HH:mm:ss');
                }
            },
            { title: '抵息券说明', dataIndex: 'remark', key: 'remark' }
        ]
    }

    onCopy = () => {
        message.success('复制成功', 2);
    }

    changeYbOrderId = (id, record) => {
        this.setState({
            visible: true,
            id,
            inputVal: record.yborderid
        })
    }

    handleSearch = (obj) => {
        const params = obj
        this.getTableData({ ...params });
    }
    
    getTableData = (params) => {
        this.setState({
            loading: true
        })
        this.setState({
            params
        })
        axios({
            url: '/hs/admin/loan/couponQuery',
            method: 'post',
            data: {
                ...params,
                pageSize: 15,
                pageNum: 1
            }
        }).then((res) => {
            if(res) {
                this.setState({
                    data: res.data,
                    loading: false,
                })
            }
        })
    }
    componentDidMount(){
        this.getTableData()
    }

    render() {
        const { data, loading, visible, inputVal } = this.state;
        return (
            <div>
                <SearchList submit={this.handleSearch}/>
                <Table
                    columns={this.columns}
                    dataSource={data}
                    loading={loading}
                    bordered
                    rowKey={'id'}
                />
            </div>
        );
    }
}
export default YiBaoId